package com.mezz.bones.user.application.executor.cmd.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mezz.bones.user.application.domain.cmd.SysMenuCreateCmd;
import com.mezz.bones.user.application.domain.cmd.SysMenuDeleteCmd;
import com.mezz.bones.user.application.domain.cmd.SysMenuUpdateCmd;
import com.mezz.bones.user.application.domain.qry.SysMenuPageForAppQry;
import com.mezz.bones.user.application.domain.res.SysMenuDetailForAppResponse;
import com.mezz.bones.user.application.domain.res.SysMenuPageForAppResponse;
import com.mezz.bones.user.application.executor.cmd.ISysMenuExecutor;
import com.mezz.bones.user.application.repository.ISysMenuRepository;
import com.mezz.bones.user.client.domain.entity.SysMenu;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @Author: mezz
 * @Date: 2025/1/15 14:25
 * @Description: 菜单管理执行器实现
 * @Version: 1.0
 **/

@Service
@Slf4j
@AllArgsConstructor
public class SysMenuExecutorImpl implements ISysMenuExecutor {

    private final ISysMenuRepository sysMenuRepository;

    @Override
    public void execSysMenuCreateCmd(SysMenuCreateCmd cmd) {
        SysMenu add = new SysMenu();
        BeanUtils.copyProperties(cmd, add);
        add.setCreateBy(cmd.getOperatorId());
        add.setCreateName(cmd.getOperatorName());
        add.setCreateTime(cmd.getOperatorTime());
        sysMenuRepository.save(add);
    }

    @Override
    public void execSysMenuUpdateCmd(SysMenuUpdateCmd cmd) {
        SysMenu update = new SysMenu();
        BeanUtils.copyProperties(cmd, update);
        update.setUpdateBy(cmd.getOperatorId());
        update.setUpdateName(cmd.getOperatorName());
        update.setUpdateTime(cmd.getOperatorTime());
        sysMenuRepository.updateById(update);
    }

    @Override
    public void execSysMenuDeleteCmd(SysMenuDeleteCmd cmd) {
        SysMenu delete = new SysMenu();
        delete.setId(cmd.getId());
        delete.setUpdateBy(cmd.getOperatorId());
        delete.setUpdateName(cmd.getOperatorName());
        delete.setUpdateTime(cmd.getOperatorTime());
        delete.setIsDel(1);
        sysMenuRepository.updateById(delete);
    }

    @Override
    public SysMenuDetailForAppResponse detailForApp(String id) {
        SysMenu sysMenu = sysMenuRepository.getByIdWithException(id);
        SysMenuDetailForAppResponse res = new SysMenuDetailForAppResponse();
        BeanUtils.copyProperties(sysMenu, res);
        return res;
    }

    @Override
    public Page<SysMenuPageForAppResponse> pageForApp(SysMenuPageForAppQry qry) {
        // TODO: 实现分页查询逻辑
        return null;
    }

}